package se.chalmers.tda366.crumble.gui.dialogs;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.List;

import javax.swing.ComboBoxModel;
import javax.swing.DefaultComboBoxModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import se.chalmers.tda366.crumble.core.IFeed;
import se.chalmers.tda366.crumble.gui.utils.CloseActionListener;
import se.chalmers.tda366.crumble.gui.utils.GuiObserv;
import se.chalmers.tda366.crumble.resources.Constants;



/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class RemoveFeedView extends JPanel {
	
	private List<IFeed> feeds;
	
	public RemoveFeedView(List<IFeed> feeds){
		this.feeds=feeds;
		initGUI();
		initCtrl();
	}
	
	private void initCtrl() {
		cancelButton.addActionListener(new CloseActionListener());
		removeButton.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				GuiObserv.getInstance().fireNotify(((JButton)evt.getSource()).getParent(), Constants.Actions.REMOVE_FEED);
			}
		});
	}

	private void initGUI() {
		try {
			{
				this.setLayout(null);
				this.setPreferredSize(new java.awt.Dimension(410, 160));
				this.setSize(410, 160);
			}
			{
				removeFeedHeadlineLabel = new JLabel();
				this.add(removeFeedHeadlineLabel);
				removeFeedHeadlineLabel.setText("Remove subscription...");
				removeFeedHeadlineLabel.setBounds(44, 12, 326, 15);
				removeFeedHeadlineLabel.setFont(se.chalmers.tda366.crumble.resources.Constants.HEADLINEFONT);
			}
			{
				removeFeedDescriptionLabel = new JLabel();
				this.add(removeFeedDescriptionLabel);
				removeFeedDescriptionLabel.setText("Select subscription to remove:");
				removeFeedDescriptionLabel.setBounds(40, 68, 177, 15);
			}
			{
				ComboBoxModel removeFeedComboBoxModel = 
							new DefaultComboBoxModel(feeds.toArray());
				removeFeedComboBox = new JComboBox();
				this.add(removeFeedComboBox);
				removeFeedComboBox.setModel(removeFeedComboBoxModel);
				removeFeedComboBox.setBounds(225, 64, 145, 22);
			}
			{
				removeButton = new JButton();
				this.add(removeButton);
				removeButton.setText("Remove");
				removeButton.setBounds(296, 108, 75, 34);
			}
			{
				cancelButton = new JButton();
				this.add(cancelButton);
				cancelButton.setText("Cancel");
				cancelButton.setBounds(217, 108, 68, 33);
			}
		} catch(Exception e) {
			e.printStackTrace();
		}
	}
	
	public IFeed getFeed(){
		return (IFeed) removeFeedComboBox.getSelectedItem();
	}
	
	private JLabel removeFeedHeadlineLabel;
	private JComboBox removeFeedComboBox;
	private JButton cancelButton;
	private JButton removeButton;
	private JLabel removeFeedDescriptionLabel;

}
